import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:psi/entity/response/login_resp.dart';
import 'package:psi/theme/app_colors.dart';
import 'package:psi/utils/utils.dart';
import 'package:psi/utils/widget_util.dart';
import 'package:psi/widgets/text_widget.dart';

import '../../../services/user_logic.dart';
import '../../../widgets/app_bar.dart';
import '../../../widgets/avatar.dart';
import 'me_logic.dart';

class MePage extends StatelessWidget {
  final logic = Get.put(MeLogic());
  final state = Get.find<MeLogic>().state;
  final userLogic = Get.find<UserLogic>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        title: "我的",
        showBack: false,
      ),
      body: Column(
        children: [
          Container(
            height: 200,
            width: double.infinity,
            color: Color(0xFF4474FF),
            child: GetBuilder<UserLogic>(
                id: "userInfo",
                builder: (user) {
                  return Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Avatar(
                        imagePath: user.user.value.avatar,
                        onTap: logic.changeAvatar,
                      ),
                      16.verticalSpace,
                      TextWidget(
                        user.user.value.name,
                        color: Colors.white,
                        fontSize: 20.sp,
                        fontWeight: FontWeight.bold,
                      ),
                    ],
                  );
                }),
          ),
          Expanded(
              child: Container(
            padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 16.w),
            child: WidgetUtil.listViewWithSeparated(
              children: state.menus.map((e) {
                return WidgetUtil.getCardItem(
                    onTap: e.onTap,
                    child: Row(
                      children: [
                        WidgetUtil.assetImage(
                          e.imageName,
                          size: 16.w,
                        ),
                        12.horizontalSpace,
                        TextWidget(
                          e.title,
                        ),
                        Spacer(),
                        e.type == 0
                            ? TextWidget(
                                e.subTitle,
                                color: Color(0xFF666666),
                              )
                            : Icon(Icons.chevron_right_rounded)
                      ],
                    ));
              }).toList(),
            ),
          )),
          WidgetUtil.getCardItem(
              onTap: logic.logout,
              color: Color(0xFFD7392E),
              child: TextWidget(
                "退出登录",
                color: Colors.white,
                fontWeight: FontWeight.bold,
              )),
          16.verticalSpace
        ],
      ),
    );
  }
}
